﻿namespace ProjetoModeloDDD.Domain.Services
{
    using ProjetoModeloDDD.Domain.Interfaces.Repositories;
    using ProjetoModeloDDD.Domain.Interfaces.Services;
    using System;
    using System.Collections.Generic;

    /// <summary>
    /// The service base.
    /// </summary>
    /// <typeparam name="TEntity">
    /// </typeparam>
    public class ServiceBase<TEntity> : IDisposable, IServiceBase<TEntity> where TEntity : class
    {
        private readonly IRepositoryBase<TEntity> _repository;

        public ServiceBase(IRepositoryBase<TEntity> repository)
        {
            this._repository = repository;
        }

        public void Add(TEntity obj)
        {
            this._repository.Add(obj);
        }

        public TEntity GetById(int id)
        {
            return this._repository.GetbyId(id);
        }

        public IEnumerable<TEntity> GetAll()
        {
            return this._repository.GetAll();
        }

        public void Update(TEntity obj)
        {
            this._repository.Update(obj);
        }

        public void Remove(TEntity obj)
        {
            this._repository.Remove(obj);
        }

        public void Dispose()
        {
            this._repository.Dispose();
        }
    }
}